<?php

namespace Biz\model\brandAccount;

use Doraemon\pockets\datebase\BaseDbModel;

class BrandAccountInfo extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_store';

    const _DATABASE_ = 'store';

    const _TABLE_NAME = 'brand_account_info';

    const ACCOUNT_TYPE_BRAND = 1;//品牌
    const ACCOUNT_TYPE_SHOP = 2;//店铺
    const ACCOUNT_TYPE = [
        self::ACCOUNT_TYPE_BRAND => '品牌',
        self::ACCOUNT_TYPE_SHOP => '店铺'
    ];

    const ACCOUNT_TAG_BRAND = 1;
    const ACCOUNT_TAG_DESIGN = 2;
    const ACCOUNT_TAG_BUY = 3;
    const ACCOUNT_TAG_WEB = 4;
    const ACCOUNT_TAG_SELL = 5;
    const ACCOUNT_TAG_FACTORY = 6;
    const ACCOUNT_TAG_MAP = [
        self::ACCOUNT_TAG_BRAND => '品牌',
        self::ACCOUNT_TAG_DESIGN => '设计品牌',
        self::ACCOUNT_TAG_BUY => '买手店',
        self::ACCOUNT_TAG_WEB => '网店',
        self::ACCOUNT_TAG_SELL => '经销商',
        self::ACCOUNT_TAG_FACTORY => '直销工厂',
    ];

    //账户状态
    const ACCOUNT_STATUS_DEFAULT = 0;//待定
    const ACCOUNT_STATUS_USED = 1;//启用
    const ACCOUNT_STATUS_EXPIRE = 2;//已过期
    const ACCOUNT_STATUS_DEL = 9;//删除
    const ACCOUNT_STATUS_MAP = [
        self::ACCOUNT_STATUS_DEFAULT => '待定',
        self::ACCOUNT_STATUS_USED => '启用',
        self::ACCOUNT_STATUS_EXPIRE => '已过期',
    ];

    //认证状态
    const AUTH_STATUS_DEFAULT = BrandAccountAuth::AUTH_STATUS_DEFAULT;//待审核
    const AUTH_STATUS_PASS = BrandAccountAuth::AUTH_STATUS_PASS;//审核通过
    const AUTH_STATUS_NOPASS = BrandAccountAuth::AUTH_STATUS_NOPASS;//审核不通过
    const AUTH_STATUS_USED = BrandAccountAuth::AUTH_STATUS_USED;//使用中
    const AUTH_STATUS_EXPIRE = BrandAccountAuth::AUTH_STATUS_EXPIRE;//认证过期
    const AUTH_STATUS_DEL = BrandAccountAuth::AUTH_STATUS_DEL;//删除
    const AUTH_STATUS_MAP = BrandAccountAuth::AUTH_STATUS_MAP;

    //消息通知code
    const SEND_CODE_PASS = 501;//通过
    const SEND_CODE_NOPASS = 502;//拒绝
    const SEND_CODE_OVER = 503;// 过期
    // 店铺主页店铺
    const IS_MAIN_SHOP_SHOW = 1;
    const IS_MAIN_SHOP_UNSHOW = 0;

    public static function getAllByWhere($where = [], $files = '*')
    {
        $data = self::select($files, $where);
        return $data;
    }

    public static function getOneByWhere($where = [], $files = '*')
    {
        $data = self::get($files, $where);
        return $data;
    }

    public static function insertData($data)
    {
        if (!isset($data['add_time'])) {
            $data['add_time'] = date('Y-m-d H:i:s');
        }
        if (!isset($data['edit_time'])) {
            $data['edit_time'] = date('Y-m-d H:i:s');
        }
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return self::id();
    }

    public static function updateData($data, $where)
    {
        if (!isset($data['edit_time'])) {
            $data['edit_time'] = date('Y-m-d H:i:s');
        }
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return true;
    }


}